<!DOCTYPE html>
<meta charset="UTF-8">
<h2>右击节点显示菜单</h2>
<div style="margin: 10px 0;"></div>
<ul id="contextmenu_tree_id" data-type="tree"
	data-defs="
			method:'get',url: '${rc.contextPath}/assets/ui/jww/demo/testdata/tree_data1.json',
			animate: true,
			onContextMenu: function(e,node){
				e.preventDefault();
				$(this).tree('select',node.target);
				$('#treecontextmenu').menu('show',{
					left: e.pageX,
					top: e.pageY
				});
			}
		"></ul>
<div id="treecontextmenu" data-type="menu" style="width: 120px;">
	<div onclick="append()" data-defs="iconCls:'icon-add'">增加</div>
	<div onclick="remove()" data-defs="iconCls:'icon-delete'">删除</div>
	<div class="menu-sep"></div>
	<div onclick="expand()">展开</div>
	<div onclick="collapse()">关闭</div>
</div>
<script type="text/javascript">
	function append() {
	    var t = $('#contextmenu_tree_id');
	    var node = t.tree('getSelected');
	    t.tree('append', {
	        parent : (node ? node.target : null),
	        data : [ {
		        text : 'new node1'
	        }, {
		        text : 'new node2'
	        } ]
	    });
    }
    function remove() {
	    var node = $('#contextmenu_tree_id').tree('getSelected');
	    $('#contextmenu_tree_id').tree('remove', node.target);
    }
    function collapse() {
	    var node = $('#contextmenu_tree_id').tree('getSelected');
	    $('#contextmenu_tree_id').tree('collapse', node.target);
    }
    function expand() {
	    var node = $('#contextmenu_tree_id').tree('getSelected');
	    $('#contextmenu_tree_id').tree('expand', node.target);
    }
</script>
